import requests
import os

# 图片的URL地址
url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"

# 指定桌面的路径
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")

# 提取图片文件名
file_name = url.split("/")[-1]

# 拼接保存图片的完整路径
save_path = os.path.join(desktop_path, file_name)

# 发送HTTP GET请求，下载图片
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 保存图片到桌面
    with open(save_path, 'wb') as f:
        f.write(response.content)
    print("图片已成功保存到桌面：", save_path)
else:
    print("下载图片失败")
